import java.util.Random;

public class Test {

    private static final int ARRAY_SIZE = 10_000_000;
    private static final int MAX_VALUE = 100;
    private static int[] array = new int[ARRAY_SIZE];
    private static long evenIndexSum = 0;
    private static long oddIndexSum = 0;

    public static void main(String[] args) throws InterruptedException {
        // 生成随机数组
        Random random = new Random();
        for (int i = 0; i < ARRAY_SIZE; i++) {
            array[i] = random.nextInt(MAX_VALUE) + 1;
        }

        // 记录开始时间
        long startTime = System.currentTimeMillis();

        // 创建两个线程
        Thread evenIndexThread = new Thread(() -> {
            for (int i = 0; i < ARRAY_SIZE; i += 2) {
                evenIndexSum += array[i];
            }
        });

        Thread oddIndexThread = new Thread(() -> {
            for (int i = 1; i < ARRAY_SIZE; i += 2) {
                oddIndexSum += array[i];
            }
        });

        // 启动线程
        evenIndexThread.start();
        oddIndexThread.start();

        // 等待两个线程完成
        evenIndexThread.join();
        oddIndexThread.join();

        // 计算总和
        long totalSum = evenIndexSum + oddIndexSum;

        // 记录结束时间
        long endTime = System.currentTimeMillis();

        // 输出结果
        System.out.println("偶数下标元素的和: " + evenIndexSum);
        System.out.println("奇数下标元素的和: " + oddIndexSum);
        System.out.println("总和: " + totalSum);
        System.out.println("程序执行时间: " + (endTime - startTime) + " ms");
    }
}
